home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * Util.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
- if (!IS.isModuleInitialized("IS.NOF.Util"))
- {
- //TODO: get out these functions !
-
- /** Populate drop down list of templates.
- **/
- function initTemplateCombo(o, path, s, dir, excludes)
- {
- var iter = new ActiveXObject(NOF.ProgId.FSIDirIterator);
-
- var templatesResources = NOF.UTIL.ResourceBundle.getBundle(
- "PhotoGallery/PhotoGalleryTemplates", NOF.UTIL.DefaultLocale );
-
- //alert( " templatesResources = " + templatesResources);
-
- var index = 0;
- var i = 0;
- iter.DefineSearch(dir + path, '*');
-
- var mustExclude = (arguments.length==5);
-
- o.options.length = 0;
-
- for (;;)
- {
- var p = iter.GetNext();
- if (!p.length)
- break;
-
- if(mustExclude){
- if(typeof(excludes)=="function"){
- if( excludes(p) )
- continue;
- }
- }
-
- var q = p.split('.');
- if (q.length > 1)
- {
- if (q[q.length - 1].split('\\').length == 1)
- continue;
- }
- p = p.split('\\');
- p = p[p.length - 1];
-
- if(mustExclude){
-
- if( excludes.constructor == Array ) {
- if( excludes.containsItem(p) >= 0 ){
- continue;
- }
- }
- }
-
- if (s == p)
- index = i;
- var theOption = document.createElement("OPTION");
- o.options.add(theOption);
- var value = p.replace (/\s/g, "");
- theOption.innerText = ( templatesResources != null && templatesResources.getProperty(value) != null ) ? templatesResources.getProperty(value) : p;
- theOption.value = p;
- i++;
- }
- o.selectedIndex = index;
- iter = null;
- }
-
-
- function getFileName( filePath ){
-
- var theName = filePath.split('\\');
- return theName[theName.length - 1];
-
- }
-
-
- function orientationToValue(i) {
- switch (i)
- {
- case 0:
- return 0;
- case 1:
- return 90;
- case 2:
- return 270;
- default:
- return 180;
- }
- }
-
- function orientationToIndex(v) {
- switch (v - 0) {
- case 0:
- return 0;
- case 90:
- return 1;
- case 270:
- return 2;
- default:
- return 3;
- }
- }
-
- function spin(o, v, f) {
- o.value = o.value - 0 + v;
- eval(f);//();
- }
-
- function toint(i) {
- var s = '' + i;
- return s.split('.')[0] - 0;
- }
-
- function readFile(fileURL){
- var app = new ActiveXObject(NOF.ProgId.FSIApplication);
- if(app.DoesFileExist(fileURL)){
- var app2 = new ActiveXObject(NOF.ProgId.FSIApplication2);
- return app2.ReadFile(fileURL);
- } else {
- return null;
- }
- }
-
- function getFSIBaseDirectory(){
- var app = new ActiveXObject(NOF.ProgId.FSIApplication);
- var base = app.SystemDirectory;
- var dir = '';
- if(base.lastIndexOf("\\") == base.length-1){
- dir = base+"FSI";
- } else {
- dir = base+"\\FSI";
- }
- base = null;
- app = null;
- return dir;
- }
-
- function trim(str) {
- i = 0;
- go = true;
- while (go) {
- c = str.charAt(i);
- if (c == ' ' || c == '\t' || c == '\n') {
- i++;
- }
- else {
- go = false;
- }
- if (i>=str.length) {
- go = false;
- }
- }
- str = str.substr(i);
- i = str.length;
- go = true;
- while (go) {
- c = str.charAt(i);
- if (c == ' ' || c == '\t' || c == '\n') {
- i--;
- }
- else {
- go = false;
- }
- if (i==0) {
- go = false;
- }
- }
- str = str.substr(0,i);
- return str;
- }
-
-
- function showTooltip( source, helpHTML, iWidth, iHeight, ix, iy ) {
-
- var oPopup = window.createPopup();
- var oPopBody = oPopup.document.body;
- oPopBody.style.backgroundColor = "lightyellow";
- oPopBody.style.border = "solid black 1px";
- oPopBody.innerHTML = helpHTML;
- //oPopup.show( ( (ix) ? ix : (-1*(iWidth/2)) ), ((iy) ? iy : 10), iWidth, iHeight, source);
- var app2 = new ActiveXObject(NOF.ProgId.FSIApplication2);
- oPopup.show( ( (ix) ? ix : (-1*(iWidth/2)) ), ((iy) ? iy : 10), iWidth * app2.LogPixelsX / 96, iHeight * app2.LogPixelsY / 96, source);
- app2 = null;
- }
-
-
- /****h* NOF_JavaScript_Library/NOF.Util
- *
- * NAME
- * NOF.Util
- *
- * DESCRIPTION
- *
- * External dependencies: none
- ****/
-
- /**
- * Constructor
- **/
- function NOF_Util(){
- this.__proto__ = NOF_Util.prototype;
- }
- {
- var method = NOF_Util.prototype;
-
- method.toFullPath = function (path) {
- var temp = path.split("\\");
- var path = "";
- for (var i = 0; i < temp.length - 1; i++ )
- path += temp[i] + "\\\\";
- path += temp[temp.length-1];
-
- return path;
- }
-
- method.removeFullPath = function (path) {
- var temp = path.split("\\\\");
- var path = "";
- for (var i = 0; i < temp.length - 1; i++ )
- path += temp[i] + "\\";
- path += temp[temp.length-1];
-
- return path;
- }
-
- method.formatDate = function (d) {
- if ( d == 0 || d == null)
- return "";
- var theDate = new Date(d * 1000);
- var theMonth = NOF.Util.shortDate(theDate.getMonth() + 1);
- var theDay = NOF.Util.shortDate(theDate.getDate());
- var theYear = NOF.Util.shortDate(theDate.getYear());
-
- return '' + theMonth + '-' + theDay + '-' + theYear;
- }
-
- method.shortDate = function (d) {
- var s = '' + d;
- switch (s.length) {
- case 0:
- return '00';
- case 1:
- return '0' + s;
- case 4:
- return s.substr(2, 2);
- default:
- return s;
- }
- }
-
- method.generateGuid = function (uniqueId) {
- var guid = "";
- for (var i = 1; i <= 32; i++) {
- var n = Math.floor(Math.random() * 16.0).toString(16);
- guid += n;
- if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
- guid += "-";
- }
- guid += "-" + uniqueId;
- return guid;
- }
-
- method.fixDouble = function (validator, value) {
- var newValue = value;
- if (validator != null) {
- var separator = ".";
- var tSeparator = ",";
- var dLength = validator.minLength;
-
- if (value == null || validator.isEmptyString(value)) {
- newValue = "0";
- var d = "0";
- if (dLength > 0) {
- while (d.length < dLength)
- d = d + "0";
- newValue += separator + d;
- }
- return newValue;
- }
- //debugger;
- var tIndex = value.lastIndexOf (",");
- var index = value.lastIndexOf (".");
- if (tIndex > index) {
- separator = ",";
- tSeparator = ".";
- var aux = index;
- index = tIndex;
- tIndex = aux;
- }
- if (index == -1)
- index = value.length;
-
-
- var w = value.substring (0,index);
- var d = value.substring (index+1);
-
- // check integer part
- if (w.indexOf(".") != -1) {
- var re = new RegExp ("\\.", "g");
- w = w.replace(re, "");
- }
- if (w.indexOf(",") != -1) {
- var re = new RegExp (",", "g");
- w = w.replace(re, "");
- }
-
- if (tIndex != -1) {
- var newWhole = "";
- var intWhole = w;
- var toContinue = true;
- while (toContinue) {
- var len = intWhole.length;
- if (len > 3) {
- newWhole = tSeparator + intWhole.substring (len-3) + newWhole;
- intWhole = intWhole.substring(0, len-3);
- }
- else {
- newWhole = intWhole + newWhole;
- toContinue = false;
- }
- }
- w = newWhole;
- }
-
- // check decimal part
- if (d.length > dLength)
- d = d.substring (0, dLength);
- else if (d.length < dLength)
- while (d.length < dLength)
- d = d + "0";
-
- newValue = w;
- if (d.length > 0)
- newValue += separator + d;
- }
- else if (value == null || value.trim() == "")
- return "0.00";
-
- return newValue;
- }
- }
-
- NOF.__proto__.Util = new NOF_Util();
-
- }
-
-
-
-
-
-
-